package m.store.model;

import m.base.model.StoreInfo;
import m.common.model.*;
import m.common.model.type.FieldType;
import m.common.model.util.ModelQueryList;
import m.common.model.util.QueryCondition;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@TableMeta(name="ts_goods_out_record",description="商品出库记录")
public class GoodsOutRecord extends GoodsRecordModel implements MigrationModel {
    @Override
    public List<String> migrationOidList(String storeOid) throws Exception {
        return ModelQueryList.getModelList(this.getClass(),new String[]{"oid"},null,
                        QueryCondition.eq("store.oid",storeOid))
                .stream().map(Model::getOid).collect(Collectors.toList());
    }
    @LinkTableMeta(name="store_oid",table= StoreInfo.class,description="所属商户")
    private StoreInfo store;
    @LinkTableMeta(name="sale_oid",table= SaleInfo.class,description="所属出库信息")
    private SaleInfo sale;
    @LinkTableMeta(name="goods_oid",table= StoreGoods.class,description="商品")
    private StoreGoods goods;
    @LinkTableMeta(name="record_oid",table= GoodsStockRecord.class,description="库存记录")
    private GoodsStockRecord record;
    @LinkTableMeta(name="back_record_oid",table= GoodsOutRecord.class,description="退记录")
    private GoodsOutRecord backRecord;

    @FieldMeta(name="oper_date",type= FieldType.DATE,description="操作时间")
    private Date operDate;
    @FieldMeta(name="num",type= FieldType.INT,description="数量")
    private Integer num;
    @FieldMeta(name="price",type= FieldType.DOUBLE,description="单价")
    private Double price;
    @FieldMeta(name="preferential",type= FieldType.DOUBLE,description="总优惠")
    private Double preferential;
    @FieldMeta(name="sale_amount",type= FieldType.DOUBLE,description="金额")
    private Double saleAmount;
    @FieldMeta(name="preferential_price",type= FieldType.DOUBLE,description="优惠后单价")
    private Double preferentialPrice;
    @FieldMeta(name = "remark",type = FieldType.STRING,length = 500,description = "备注")
    private String remark;

    @FieldMeta(name="stock_price",type= FieldType.DOUBLE,description="库存单价|记录库存单价方便计算盈利")
    private Double stockPrice;
    //冗余信息
    @FieldMeta(name="refund_num",type= FieldType.INT,description="退货数量")
    private Integer refundNum;
    @FieldMeta(name="refund_amount",type= FieldType.DOUBLE,description="退货金额")
    private Double refundAmount;
    @FieldMeta(name="surplus_num",type= FieldType.INT,defaultValue = "0",description="剩余数量")
    private Integer surplusNum;
    @FieldMeta(name="surplus_amount",type= FieldType.DOUBLE,defaultValue = "0",description="剩余金额")
    private Double surplusAmount;
    @FieldMeta(name="gain_amount",type= FieldType.DOUBLE,defaultValue = "0",description="盈利金额")
    private Double gainAmount;

    public GoodsOutRecord getBackRecord() {
        return backRecord;
    }

    public void setBackRecord(GoodsOutRecord backRecord) {
        this.backRecord = backRecord;
    }

    public Double getStockPrice() {
        return stockPrice;
    }

    public void setStockPrice(Double stockPrice) {
        this.stockPrice = stockPrice;
    }

    public Double getGainAmount() {
        return gainAmount;
    }

    public void setGainAmount(Double gainAmount) {
        this.gainAmount = gainAmount;
    }

    public StoreGoods getGoods() {
        return goods;
    }

    public void setGoods(StoreGoods goods) {
        this.goods = goods;
    }

    public Double getPreferentialPrice() {
        return preferentialPrice;
    }

    public void setPreferentialPrice(Double preferentialPrice) {
        this.preferentialPrice = preferentialPrice;
    }

    public Integer getRefundNum() {
        return refundNum;
    }

    public void setRefundNum(Integer refundNum) {
        this.refundNum = refundNum;
    }

    public Double getRefundAmount() {
        return refundAmount;
    }

    public void setRefundAmount(Double refundAmount) {
        this.refundAmount = refundAmount;
    }

    public Integer getSurplusNum() {
        return surplusNum;
    }

    public void setSurplusNum(Integer surplusNum) {
        this.surplusNum = surplusNum;
    }

    public Double getSurplusAmount() {
        return surplusAmount;
    }

    public void setSurplusAmount(Double surplusAmount) {
        this.surplusAmount = surplusAmount;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public StoreInfo getStore() {
        return store;
    }

    public void setStore(StoreInfo store) {
        this.store = store;
    }

    public SaleInfo getSale() {
        return sale;
    }

    public void setSale(SaleInfo sale) {
        this.sale = sale;
    }

    public Date getOperDate() {
        return operDate;
    }

    public void setOperDate(Date operDate) {
        this.operDate = operDate;
    }

    public Integer getNum() {
        return num;
    }

    public void setNum(Integer num) {
        this.num = num;
    }

    public Double getPrice() {
        return price;
    }

    public void setPrice(Double price) {
        this.price = price;
    }

    public Double getPreferential() {
        return preferential;
    }

    public void setPreferential(Double preferential) {
        this.preferential = preferential;
    }

    public Double getSaleAmount() {
        return saleAmount;
    }

    public void setSaleAmount(Double saleAmount) {
        this.saleAmount = saleAmount;
    }

    public GoodsStockRecord getRecord() {
        return record;
    }

    public void setRecord(GoodsStockRecord record) {
        this.record = record;
    }
}
